# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Lucas Hoffmann
# Contributor: Giancarlo Razzolini <grazzolini@archlinux.org>
# Contributor: Kazuo Teramoto <kaz.rag at gmail.com>

pkgname=afew
pkgver=3.0.1
pkgrel=6
pkgdesc='Initial tagging script for notmuch mail'
arch=('any')
url=https://github.com/afewmail/afew
license=('custom:BSD')
depends=('notmuch' 'python-chardet' 'python-dkim' 'python-setuptools')
makedepends=('python-build' 'python-installer' 'python-setuptools-scm'
             'python-sphinx' 'python-wheel')
checkdepends=('python-freezegun')
source=("https://files.pythonhosted.org/packages/source/a/afew/afew-$pkgver.tar.gz")
sha256sums=('ce857fe1a3bc0982c1dac81aef66cacc148e4f9db06da720f869392af1c2ee72')
b2sums=('9ce125ec2359f7cf4630b9602b3068327adc06a699d325c90bc9b545df9ce7f3a62623cc733dfec55ee3e51523e4512ebec04e7186470fc56bb1589a7141cbc9')

build() {
  cd afew-$pkgver
  python -m build --wheel --skip-dependency-check --no-isolation
  PYTHONPATH="build:$PYTHONPATH" sphinx-build -b man docs build
}

check() {
  cd afew-$pkgver
  python -m unittest discover afew/tests
}

package() {
  cd afew-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm644 -t "$pkgdir"/usr/share/man/man1 build/afew.1

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/$pkgname-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
